package gson;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
 * Title:
 * Created by Myth on 2017/8/16.
 */
public class TestGson {
    public static void main(String[] args) {
        // json   [ ] 代表数组    { } 代表 一个json对象
        String jsonString = "{\"HeWeather5\":[{\"basic\":{\"city\":\"沈阳\",\"cnty\":\"中国\",\"id\":\"CN101070101\",\"lat\":\"41.79676819\",\"lon\":\"123.42909241\",\"update\":{\"loc\":\"2017-08-16 07:53\",\"utc\":\"2017-08-15 23:53\"}},\"daily_forecast\":[{\"astro\":{\"mr\":\"23:59\",\"ms\":\"13:42\",\"sr\":\"04:56\",\"ss\":\"18:45\"},\"cond\":{\"code_d\":\"302\",\"code_n\":\"302\",\"txt_d\":\"雷阵雨\",\"txt_n\":\"雷阵雨\"},\"date\":\"2017-08-16\",\"hum\":\"75\",\"pcpn\":\"12.7\",\"pop\":\"99\",\"pres\":\"1007\",\"tmp\":{\"max\":\"27\",\"min\":\"20\"},\"uv\":\"7\",\"vis\":\"17\",\"wind\":{\"deg\":\"5\",\"dir\":\"北风\",\"sc\":\"微风\",\"spd\":\"7\"}},{\"astro\":{\"mr\":\"23:45\",\"ms\":\"14:48\",\"sr\":\"04:57\",\"ss\":\"18:43\"},\"cond\":{\"code_d\":\"306\",\"code_n\":\"302\",\"txt_d\":\"中雨\",\"txt_n\":\"雷阵雨\"},\"date\":\"2017-08-17\",\"hum\":\"77\",\"pcpn\":\"9.8\",\"pop\":\"98\",\"pres\":\"1008\",\"tmp\":{\"max\":\"27\",\"min\":\"20\"},\"uv\":\"7\",\"vis\":\"15\",\"wind\":{\"deg\":\"174\",\"dir\":\"南风\",\"sc\":\"微风\",\"spd\":\"5\"}},{\"astro\":{\"mr\":\"00:51\",\"ms\":\"15:51\",\"sr\":\"04:58\",\"ss\":\"18:42\"},\"cond\":{\"code_d\":\"302\",\"code_n\":\"101\",\"txt_d\":\"雷阵雨\",\"txt_n\":\"多云\"},\"date\":\"2017-08-18\",\"hum\":\"75\",\"pcpn\":\"9.3\",\"pop\":\"100\",\"pres\":\"1010\",\"tmp\":{\"max\":\"28\",\"min\":\"20\"},\"uv\":\"6\",\"vis\":\"16\",\"wind\":{\"deg\":\"59\",\"dir\":\"东北风\",\"sc\":\"微风\",\"spd\":\"4\"}}],\"status\":\"ok\"}]}";

        JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject();

        JsonArray jsonArray = jsonObject.getAsJsonArray("HeWeather5");

        String weatherContent = jsonArray.get(0).toString();

        Weather weather = new Gson().fromJson(weatherContent, Weather.class);

    }

}
